<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:uddi="urn:uddi-org:api_v3">
	<xsl:output method="xml" encoding="UTF-8"/>

	<xsl:include href="keyedreference.xsl"/>
	<xsl:include href="keyedreferencegroup.xsl"/>

	<!-- Match the category bag UDDI element -->
	<xsl:template match="uddi:categoryBag">
		<xsl:variable name="keyedReferenceCount"><xsl:value-of select="count(uddi:keyedReference)"/></xsl:variable>
		<xsl:variable name="keyedReferenceGroupCount"><xsl:value-of select="count(uddi:keyedReferenceGroup)"/></xsl:variable>
		<fieldset>
			<legend>Category Bag [<xsl:value-of select="$keyedReferenceCount + $keyedReferenceGroupCount"/>]</legend>
			<table>
				<tr>
					<th>
						Keyed References [<xsl:value-of select="$keyedReferenceCount"/>]
					</th>
				</tr>
				<xsl:if test="$keyedReferenceCount > 0">
				<tr>
					<td>
						<table>
							<tr>
								<th>UDDI ID</th>
								<th>KeyName</th>
								<th>KeyValue</th>
							</tr>
							<xsl:apply-templates select="uddi:keyedReference"/>
						</table>
					</td>
				</tr>
				</xsl:if>
				<tr>
					<th>
						Keyed Reference Groups [<xsl:value-of select="$keyedReferenceGroupCount"/>]
					</th>
				</tr>
				<xsl:if test="$keyedReferenceGroupCount > 0">
				<tr>
					<td>
						<table>
							<tr>
								<th>UDDI ID</th>
								<th>KeyName</th>
								<th>KeyValue</th>
							</tr>
							<xsl:apply-templates select="uddi:keyedReferenceGroup"/>
						</table>
					</td>
				</tr>
				</xsl:if>
			</table>
		</fieldset>
	</xsl:template>
	
</xsl:stylesheet>